<cfcomponent>
<cffunction name="getstates" access="public" returntype="string" hint="Returns a list of states in a specific country (default is United States)">
  <cfargument name="country" type="string" required="no" default="United States" hint="country from which we are to get the states">
  <cfquery name = "qstates" datasource="#request.dsn#" maxrows="1">
        SELECT states FROM core_states
        WHERE country_short = '#country#'
        </cfquery>
  <cfreturn qstates.states>
</cffunction>
<cffunction name="getcountries" access="public" returntype="query">
  <cfquery name = "qcountries" datasource="#request.dsn#">
        SELECT * FROM core_countries WHERE showthis ='yes'
        ORDER BY country ASC
        </cfquery>
  <cfreturn qcountries>
</cffunction>
<cffunction name="timezonedropdown" access="public" returntype="void" output="yes" hint="shows the timezone drop down box">
  <cfargument name="selected" default="5,1" required="no" hint="The selected default time zone">
  <select id="timezone_offset" name="timezone_offset">
    <option value='12,0' <cfif selected IS '12,0'>selected="selected"</cfif>>(-12:00) International Date Line West</option>
    <option value='11,0,' <cfif selected IS '11,0'>selected="selected"</cfif>>(-11:00) Midway Island, Samoa</option>
    <option value='10,0' <cfif selected IS '10,0'>selected="selected"</cfif>>(-10:00) Hawaii</option>
    <option value='9,1' <cfif selected IS '9,0'>selected="selected"</cfif>>(-09:00) Alaska</option>
    <option value='8,1' <cfif selected IS '8,1'>selected="selected"</cfif>>(-08:00) Pacific Time (US & Canada)</option>
    <option value='7,0' <cfif selected IS '7,0'>selected="selected"</cfif>>(-07:00) Arizona</option>
    <option value='7,1' <cfif selected IS '7,1'>selected="selected"</cfif>>(-07:00) Mountain Time (US & Canada)</option>
    <option value='6,0' <cfif selected IS '6,0'>selected="selected"</cfif>>(-06:00) Central America, Saskatchewan</option>
    <option value='6,1' <cfif selected IS '6,1'>selected="selected"</cfif>>(-06:00) Central Time (US & Canada), Guadalajara, Mexico city</option>
    <option value='5,0' <cfif selected IS '5,0'>selected="selected"</cfif>>(-05:00) Indiana, Bogota, Lima, Quito, Rio Branco</option>
    <option value='5,1' <cfif selected IS '5,1'>selected="selected"</cfif>>(-05:00) Eastern time (US & Canada)</option>
    <option value='4,1' <cfif selected IS '4,1'>selected="selected"</cfif>>(-04:00) Atlantic time (Canada), Manaus, Santiago</option>
    <option value='4,0' <cfif selected IS '4,0'>selected="selected"</cfif>>(-04:00) Caracas, La Paz</option>
    <option value='3,1' <cfif selected IS '3,1'>selected="selected"</cfif>>(-03:30) Newfoundland</option>
    <option value='3,1' <cfif selected IS '3,1'>selected="selected"</cfif>>(-03:00) Greenland, Brasilia, Montevideo</option>
    <option value='3,0' <cfif selected IS '3,0'>selected="selected"</cfif>>(-03:00) Buenos Aires, Georgetown</option>
    <option value='2,1' <cfif selected IS '2,1'>selected="selected"</cfif>>(-02:00) Mid-Atlantic</option>
    <option value='1,1' <cfif selected IS '1,1'>selected="selected"</cfif>>(-01:00) Azores</option>
    <option value='1,0' <cfif selected IS '1,0'>selected="selected"</cfif>>(-01:00) Cape Verde Is.</option>
    <option value='0,0' <cfif selected IS '0,0'>selected="selected"</cfif>>(00:00) Casablanca, Monrovia, Reykjavik</option>
    <option value='0,1' <cfif selected IS '0,1'>selected="selected"</cfif>>(00:00) GMT: Dublin, Edinburgh, Lisbon, London</option>
    <option value='-1,1' <cfif selected IS '-1,1'>selected="selected"</cfif>>(+01:00) Amsterdam, Berlin, Rome, Vienna, Prague, Brussels</option>
    <option value='-1,0' <cfif selected IS '-1,1'>selected="selected"</cfif>>(+01:00) West Central Africa</option>
    <option value='-2,1' <cfif selected IS '-2,1'>selected="selected"</cfif>>(+02:00) Amman, Athens, Istanbul, Beirut, Cairo, Jerusalem</option>
    <option value='-2,0' <cfif selected IS '-2,0'>selected="selected"</cfif>>(+02:00) Harare, Pretoria</option>
    <option value='-3,1' <cfif selected IS '-3,1'>selected="selected"</cfif>>(+03:00) Baghdad, Moscow, St. Petersburg, Volgograd</option>
    <option value='-3,0' <cfif selected IS '-3,0'>selected="selected"</cfif>>(+03:00) Kuwait, Riyadh, Nairobi, Tbilisi</option>
    <option value='-3.5,0' <cfif selected IS '-3.5,0'>selected="selected"</cfif>>(+03:30) Tehran</option>
    <option value='-4,0' <cfif selected IS '-4,0'>selected="selected"</cfif>>(+04:00) Abu Dhadi, Muscat</option>
    <option value='-4,1' <cfif selected IS '-4,1'>selected="selected"</cfif>>(+04:00) Baku, Yerevan</option>
    <option value='-4.5,0' <cfif selected IS '-4.5,0'>selected="selected"</cfif>>(+04:30) Kabul</option>
    <option value='-5,1' <cfif selected IS '-5,1'>selected="selected"</cfif>>(+05:00) Ekaterinburg</option>
    <option value='-5,0' <cfif selected IS '-5,0'>selected="selected"</cfif>>(+05:00) Islamabad, Karachi, Tashkent</option>
    <option value='-5.5,0' <cfif selected IS '-5.5,0'>selected="selected"</cfif>>(+05:30) Chennai, Kolkata, Mumbai, New Delhi, Sri Jayawardenepura</option>
    <option value='-5.75,0' <cfif selected IS '-5.75,0'>selected="selected"</cfif>>(+05:45) Kathmandu</option>
    <option value='-6,0' <cfif selected IS '-6,0'>selected="selected"</cfif>>(+06:00) Astana, Dhaka</option>
    <option value='-6,1' <cfif selected IS '-6,1'>selected="selected"</cfif>>(+06:00) Almaty, Nonosibirsk</option>
    <option value='-6.5,0' <cfif selected IS '-6.5,0'>selected="selected"</cfif>>(+06:30) Yangon (Rangoon)</option>
    <option value='-7,1' <cfif selected IS '-7,1'>selected="selected"</cfif>>(+07:00) Krasnoyarsk</option>
    <option value='-7,0' <cfif selected IS '-7,0'>selected="selected"</cfif>>(+07:00) Bangkok, Hanoi, Jakarta</option>
    <option value='-8,0' <cfif selected IS '-8,0'>selected="selected"</cfif>>(+08:00) Beijing, Hong Kong, Singapore, Taipei</option>
    <option value='-8,1' <cfif selected IS '-8,1'>selected="selected"</cfif>>(+08:00) Irkutsk, Ulaan Bataar, Perth</option>
    <option value='-9,1' <cfif selected IS '-9,1'>selected="selected"</cfif>>(+09:00) Yakutsk</option>
    <option value='-9,0,1' <cfif selected IS '-9,0,1'>selected="selected"</cfif>>(+09:00) Seoul, Osaka, Sapporo, Tokyo</option>
    <option value='-9,0,2' <cfif selected IS '-9,0,2'>selected="selected"</cfif>>(+09:30) Darwin</option>
    <option value='-9.5,1' <cfif selected IS '-9.5,1'>selected="selected"</cfif>>(+09:30) Adelaide</option>
    <option value='-10,0' <cfif selected IS '-10,0'>selected="selected"</cfif>>(+10:00) Brisbane, Guam, Port Moresby</option>
    <option value='-10,1' <cfif selected IS '-10,1'>selected="selected"</cfif>>(+10:00) Canberra, Melbourne, Sydney, Hobart, Vladivostok</option>
    <option value='-11,0' <cfif selected IS '-11,0'>selected="selected"</cfif>>(+11:00) Magadan, Solomon Is., New Caledonia</option>
    <option value='-12,1' <cfif selected IS '-12,1'>selected="selected"</cfif>>(+12:00) Auckland, Wellington</option>
    <option value='-12,0' <cfif selected IS '-12,0'>selected="selected"</cfif>>(+12:00) Fiji, Kamchatka, Marshall Is.</option>
    <option value='-13,0' <cfif selected IS '-13,0'>selected="selected"</cfif>>(+13:00) Nuku'alofa</option>
  </select>
</cffunction>
<cffunction name="carrierdropdown" access="public" returntype="void" output="yes" hint="shows a drop down of cellphone providers">
  <cfargument name="selected" default="none" required="no" hint="The selected value">
  <cfquery name="qcellcompanies" datasource="#request.dsn#">
    SELECT * FROM core_cellproviders
    </cfquery>
  <select name="carrier" id="carrier">
    <cfloop query="qcellcompanies">
    <option value="#qcellcompanies.cell_company#" <cfif qcellcompanies.cell_company IS selected>selected="selected"</cfif>> #qcellcompanies.cell_company# </option>
    </cfloop>
  </select>
</cffunction>
<cffunction name="genderdropdown" access="public" returntype="void" output="yes" hint="shows a drop down for gender selection">
  <cfargument name="selected" default="0" required="no" hint="The selected value">
  <select name="gender" id="gender">
    <option value="0" <cfif selected IS 0>selected="selected"</cfif>>Male</option>
    <option value="1" <cfif NOT selected IS 0>selected="selected"</cfif>>Female</option>
  </select>
</cffunction>
<cffunction name="renamefile" returntype="string" hint="renames a file and removes all illegal file characters.  Also replaces spaces with underscores for maximum compatability.">
  <cfargument name="inputfile" default="" required="yes" hint="filename uploaded to the server">
  <cfargument name="dir" default="" required="yes" hint="directory to the file relative to request.basepath">
  <cfset thefile = inputfile>
  <cfset thefile = replace(thefile, " ", "_", "ALL")>
  <cfset thefile = replace(thefile, "&", "", "ALL")>
  <cfset thefile = replace(thefile, "(", "", "ALL")>
  <cfset thefile = replace(thefile, ")", "", "ALL")>
  <cfset thefile = replace(thefile, "?", "", "ALL")>
  <cfset thefile = replace(thefile, "<", "", "ALL")>
  <cfset thefile = replace(thefile, ">", "", "ALL")>
  <cfset thefile = replace(thefile, "@", "", "ALL")>
  <cfset thefile = replace(thefile, "!", "", "ALL")>
  <cfset thefile = replace(thefile, "*", "", "ALL")>
  <cfset thefile = replace(thefile, "^", "", "ALL")>
  <cfset thefile = replace(thefile, "%", "", "ALL")>
  <cfset thefile = replace(thefile, "$", "", "ALL")>
  <cfset thefile = replace(thefile, "{", "", "ALL")>
  <cfset thefile = replace(thefile, "}", "", "ALL")>
  <cfset thefile = replace(thefile, "'", "", "ALL")>
  <cfset thefile = replace(thefile, '"', '', "ALL")>
  <cfset thefile = replace(thefile, "`", "", "ALL")>
  <cfset thefile = replace(thefile, "~", "", "ALL")>
  <cfset thefile = replace(thefile, "=", "", "ALL")>
  <cfset thefile = replace(thefile, "-", "_", "ALL")>
  <cfset thefile = replace(thefile, "/", "", "ALL")>
  <cfset thefile = replace(thefile, "\", "", "ALL")>
  <cfset thefile = replace(thefile, "[", "", "ALL")>
  <cfset thefile = replace(thefile, "]", "", "ALL")>
  <cfset fullDespath = "#request.basepath##dir##thefile#">
  <cfset fullDespath = replacenocase(FullDesPath, "//", "/", "ALL")>
  <cfset fullDespath = replacenocase(FullDesPath, "\\", "/", "ALL")>
  <cfset fullDespath = replacenocase(FullDesPath, "\", "/", "ALL")>
  <cfset fullFrompath = "#request.basepath##dir##cffile.serverfile#">
  <cfset fullFrompath = replacenocase(FullFromPath, "//", "/", "ALL")>
  <cfset fullFrompath = replacenocase(FullFromPath, "\\", "\", "ALL")>
  <cfset fullFrompath = replacenocase(FullFromPath, "\", "/", "ALL")>
  <!---if the new file name doesn't match the old one rename it--->
  <cfif NOT thefile IS inputfile>
    <cffile action = "rename" source = "#fullfrompath#" destination = "#fulldespath#" mode="777">
    <cfset outputfile = thefile>
    <cfelse>
    <cfset outputfile = inputfile>
  </cfif>
  <cfreturn outputfile>
</cffunction>
<cffunction name="redirect" access="public" returntype="void" output="yes" hint="Does a redirect">
  <cfargument name="url" default="index.cfm" required="yes" hint="url to redirect to">
  <cfargument name="msg" default="Settings Saved" required="yes" hint="Message to display">
  <cfoutput>
  <div id="messages">#msg#</div>
  #request.lang.redirectmsg#...<br />
  <a href = "#url#">#request.lang.redirectlink#</a>
  </p>
  <script language="javascript">
            pageurl = '#url#';
            setTimeout('delayer(pageurl)', 1000);
        </script>
  </cfoutput>
</cffunction>
<cffunction name="cleanforminput" access="public" returntype="struct">
  <cfargument name="fields" type="struct" required="yes">
  <cfset formfields.nothing = ''>
  <cfloop collection="#form#" item="var">
  <cfset aTempField = #evaluate('fields.' & var)#>
  <cfset aTempField = Replace(aTempField, "<", "", "ALL")>
  <cfset aTempField = Replace(aTempField, ">", "", "ALL")>
  <cfset aTempField = Replace(aTempField, "%", "", "ALL")>
  <cfset aTempField = Replace(aTempField, "(", "", "ALL")>
  <cfset aTempField = Replace(aTempField, ")", "", "ALL")>
  <cfset aTempField = Replace(aTempField, "'", "", "ALL")>
  <cfset aTempField = Replace(aTempField, "|", "", "ALL")>
  <cfset aTempField = Replace(aTempField, ";", "", "ALL")>
  <cfset aTempField = Replace(aTempField, "+", "", "ALL")>
  <cfset aTempField = Replace(aTempField, """", "", "ALL")>
  <cfset aTempField = Replace(aTempField, "javascript:", "")>
  <cfset "formfields.#var#" = aTempField>
  </cfloop>
  <cfreturn formfields>
</cffunction>
<cffunction name="cleanurlinput" access="public" returntype="struct">
  <cfargument name="urlvars" type="struct" required="yes">
  <cfset urlfields.nothing = ''>
  <cfloop collection="#url#" item="var">
  <cfset aTempField = #evaluate('urlvars.' & var)#>
  <cfset aTempField = Replace(aTempField, "<", "", "ALL")>
  <cfset aTempField = Replace(aTempField, ">", "", "ALL")>
  <cfset aTempField = Replace(aTempField, "%", "", "ALL")>
  <cfset aTempField = Replace(aTempField, "(", "", "ALL")>
  <cfset aTempField = Replace(aTempField, ")", "", "ALL")>
  <cfset aTempField = Replace(aTempField, "'", "", "ALL")>
  <cfset aTempField = Replace(aTempField, "|", "", "ALL")>
  <cfset aTempField = Replace(aTempField, ";", "", "ALL")>
  <cfset aTempField = Replace(aTempField, "+", "", "ALL")>
  <cfset aTempField = Replace(aTempField, """", "", "ALL")>
  <cfset aTempField = Replace(aTempField, "javascript:", "", "ALL")>
  <cfset "urlfields.#var#" = aTempField>
  </cfloop>
  <cfreturn urlfields>
</cffunction>
<cffunction name="showcheckall" access="public" returntype="string" hint="shows the checkall/checknone check box">
  <cfargument name="formname" type="string" required="no" default="deleteform">
  <cfargument name="fieldname" type="string" required="no" default="deleteid">
  <cfoutput>
  <cfsavecontent variable="checkallbox">
  <style>
    .chkall {
    display: none;
    }
    .chkall +label {
    display: block;
    width: 32px;
    height: 32px;
    background: url(images/checkbox_unchecked.png);
    }
    .chkall:checked + label {
    background: url(images/checkbox_checked.png);
    }		
    </style>
  <input type="checkbox" name="chkall" id="chkall" class="chkall" onclick="if (this.checked){checkAll(document.#formname#.#fieldname#)} else if(!this.checked){uncheckAll(document.#formname#.#fieldname#)};" />
  <label for="chkall" title="Select All"></label>
  </cfsavecontent>
  </cfoutput>
  <cfreturn checkallbox>
</cffunction>
<!--- Get directory entries for Ajax CFTREE --->
<cffunction name="getDirEntries" access="remote" returnType="array">
  <cfargument name="path" type="string" required="false" default="">
  <cfargument name="value" type="string" required="false" default="">
  <!--- Init variables --->
  <cfset var dir="">
  <cfset var entry="">
  <cfset var result=arrayNew(1)>
  <cfset var filepath="">
  <!--- Check if top level --->
  <cfif ARGUMENTS.value IS "">
    <!--- Yes, top level, get drives --->
    <cfdirectory action="list"
                    directory="#request.basepath#"
                    name="dir"
                    type="dir"
                    sort="name">
    <!--- Loop through dir list --->
    <cfloop query="dir">
    <!--- Add each drive/root --->
    <cfset entry=StructNew()>
    <cfset entry.value=dir.name>
    <cfset entry.display=dir.name>
    <cfset entry.img="fixed">
    <cfset ArrayAppend(result, entry)>
    </cfloop>
    <cfelse>
    <!--- Not top level, get dir list --->
    <cfdirectory action="list"
                    directory="#ARGUMENTS.value#"
                    name="dir"
                    type="dir"
                    sort="name">
    <!--- Loop through dir list --->
    <cfloop query="dir">
    <!--- Create entry --->
    <cfset entry=StructNew()>
    <!--- Use full path as value --->
    <cfset entry.value=ARGUMENTS.value & THIS.separator & dir.name>
    <!--- Use just name for display --->
    <cfset entry.display=dir.name>
    <!--- Is this a file or a dir? --->
    <cfif dir.type IS "file">
      <!--- A file, so no children --->
      <cfset entry.leafnode=TRUE>
      <!--- Use document icon --->
      <cfset entry.img="document">
      <cfelse>
      <!--- A dir, use folder icon --->
      <cfset entry.img="folder">
      <cfset entry.imgopen="folder">
    </cfif>
    <!--- Add it to the array --->
    <cfset ArrayAppend(result, entry)>
    </cfloop>
  </cfif>
  <!--- And return the results --->
  <cfreturn result>
</cffunction>
<cffunction name="createuid" access="public" returnType="string">
  <cfset new_uid = insert("-", CreateUUID(), 23)>
  <cfreturn new_uid>
</cffunction>
</cfcomponent>
